package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.sgb.kjwl.R;
import com.sgb.kjwl.view.ui.adapter.pick.PickHallBidingStatusAdapter;
import com.swgk.core.util.PickSelectEntity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import java.util.List;

public class PickHallBidingPopWindow extends BasePopWindow {

    private PickHallBidingStatusAdapter goodsTypeAdapter;
    private PickSelectEntity entity;
    private boolean isArea;
    private LinearLayout ll_next;
    private TextView tv_next;
    private TextView tv_ok;

    public PickHallBidingPopWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_goods_type3;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        MaxHeightRecyclerView recyclerView = holder.getPop().findViewById(R.id.goods_type_list);
        ll_next = holder.getPop().findViewById(R.id.ll_next);
        tv_next = holder.getPop().findViewById(R.id.tv_next);
        tv_ok = holder.getPop().findViewById(R.id.tv_ok);
        tv_next.setOnClickListener(v -> {

        });
        tv_ok.setOnClickListener(v -> {

        });
        goodsTypeAdapter = new PickHallBidingStatusAdapter(mContext, null);
        goodsTypeAdapter.setItemSelect(true);
        goodsTypeAdapter.setDefItem(-1);
        recyclerView.setLayoutManager(new GridLayoutManager(mContext, 4));
        recyclerView.setAdapter(goodsTypeAdapter);
        goodsTypeAdapter.setOnItemClick(new AdapterOnItemClick<PickSelectEntity>() {
            @Override
            public void onItemClick(PickSelectEntity provinceEntity, int position) {
//                if(null!=entity && entity.getNo().equals(provinceEntity.getNo())){
//                    onResultClick.result(null,null,null);
//                    goodsTypeAdapter.setSelected(false,provinceEntity);
//                }else{
//                    entity = provinceEntity;
                onResultClick.result(provinceEntity, null, position);
//                    goodsTypeAdapter.setSelected(true,provinceEntity);
//                }
                dissMiss();
            }
        });


        holder.getPop().findViewById(R.id.bg_pop_gray_layout).setOnClickListener(view -> dissMiss());
    }

    @Override
    public void dismiss() {
        super.dismiss();
        onDisMiss.disMiss();
    }

    public void setData(List<PickSelectEntity> list) {
        if (list == null || list.size() == 0) return;
        goodsTypeAdapter.setDatas(list);
    }

    public void setData(List<PickSelectEntity> list, boolean isArea) {
        goodsTypeAdapter.setDatas(list);
        if (isArea)
            ll_next.setVisibility(View.VISIBLE);
    }

    public void setData(List<PickSelectEntity> cityDatas, int position) {
        if (cityDatas == null || cityDatas.size() == 0) return;
        goodsTypeAdapter.setDatas(cityDatas);
        goodsTypeAdapter.setDefItem(position);
    }

    public void setData(List<PickSelectEntity> list, boolean isArea,boolean isAll) {
        if (list == null || list.size() == 0) return;
        goodsTypeAdapter.setDatas(list);
        if (isArea)
            ll_next.setVisibility(View.VISIBLE);

        if(isAll)
            goodsTypeAdapter.setDefItem(0);

    }

    public void updateData(List<PickSelectEntity> list) {
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).isCheck() == true){
                goodsTypeAdapter.setDefItem(i);
                return;
            }
        }
    }
    public void updateData(int checkId, List<PickSelectEntity> list) {
        if (list == null || list.size() == 0) return;
        goodsTypeAdapter.setDatas(list);
        goodsTypeAdapter.setDefItem(checkId);
    }

    public void setDefItem(){
        goodsTypeAdapter.setDefItem(0);
    }

    public void setDefItem(int position){
        goodsTypeAdapter.setDefItem(position);
    }
}
